package com.zoe.onelink.feign.contract;

import com.zoe.onelink.annotation.feign.FeignBody;
import feign.MethodMetadata;
import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-02-18
 */
public class RequestArgParameterProcessor implements AnnotatedParameterProcessor {

    private static final Class<FeignBody> ANNOTATION = FeignBody.class;


    @Override
    public Class<? extends Annotation> getAnnotationType() {
        return ANNOTATION;
    }

    @Override
    public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) {
        MethodMetadata data = context.getMethodMetadata();
        String name = ANNOTATION.cast(annotation).value();
        context.setParameterName(name);
        data.formParams().add(name);
        context.getMethodMetadata().bodyType(ANNOTATION);
        return true;
    }
}
